#include "Thread.hpp"
#include <unordered_map>
#include <memory>

#define NUM 10
using thread_ptr_t = std::shared_ptr<ThreadModule::Thread>;

int main()
{
    std::unordered_map<std::string, thread_ptr_t> threads; // unorderded_map容器里面 两个参数 左边线程名字右边是线程的智能指针
    // 如果想要创建多线程
    for (int i = 0; i < NUM; i++)
    {
        thread_ptr_t t = std::make_shared<ThreadModule::Thread>([]()
                                                                {
        while (true)
        {
            std::cout << "hello world" << std::endl;
            sleep(1);
        } });
        threads[t->Name()] = t;
    }

    for (auto &thread : threads)
    {
        thread.second->Start();
    }

    for (auto &thread : threads)
    {
        thread.second->Join();
    }

    // ThreadModule::Thread t([]()
    //                        {
    // while(true)
    // {
    //     std::cout << "hello world" << std::endl;
    //     sleep(1);
    // } });

    // t.Start();
    // std::cout << t.Name() << "is running" << std::endl;
    // sleep(5);

    // t.Stop();
    // std::cout << "Stop thread : " << t.Name() << "is stoped" << std::endl;
    // sleep(1);

    // t.Join();
    // std::cout << "join thread : " << t.Name() << "is joined" << std::endl;
    return 0;
}